package edu.hawaii.duedates.tests;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import edu.hawaii.duedates.parser.DueDatesParser;

/**
 * This class is responsible for testing both the Argument and DueDatesParser classes.
 * 
 * @author Anthony M. Du
 *
 */
public class TestDueDatesParser {
  private DueDatesParser parseArg;
  private final String[] args = {"-v", "-verbose", "-sort", "library", "-within", "1", "param",
                                 "-console", "-email", "someone@some.com", "-wakeup", "1"};
  
  /**
   * SetUp variables for testing DueDatesParser.
   * A DueDatesParser object instantiates and parses the passed arguments.
   */
  @Before
  public void setUp() {
    parseArg = new DueDatesParser(args);
  }
  
  /**
   * Test isOption() method.
   */
  @Test
  public void testIsOption() {
    assertEquals("Testing method isOption with a valid option", 
        true, parseArg.isOption(args[2]));
    assertEquals("Testing method isOption with an invalid option", 
        false, parseArg.isOption(args[3]));
  }
  
  /**
   * Test getOptions() method.
   */
  @Test
  public void testGetOptions() {
    assertEquals("Testing method getOptions with a value of : \"-v\"", 
                   "-v", parseArg.findOption("-v").getOptName());
    assertEquals("Testing method getOptions with a value of : \"-verbose\"",
                   "-verbose", parseArg.findOption("-verbose").getOptName());
  }
  
  /**
   * Test isParam() method.
   */
  @Test
  public void testIsParam() {
    assertEquals("Testing method isParam with a valid parameter",
        true, parseArg.isParam(args[3]));
    assertEquals("Testing method isArgument with an invalid parameter",
        false, parseArg.isParam(args[2]));
  }
  
  /**
   * Test getParams() method of a give option.
   */
  @Test
  public void testGetParams() {
    assertEquals("Testing method getParams with a value of : \"library\"", 
                   "library", parseArg.findOption("-sort").getOptParams().get(0));
    assertEquals("Testing method getParams with a value of : \"1\"",
                   "1", parseArg.findOption("-within").getOptParams().get(0));
    assertEquals("Testing method getParams with a value of : \"param\"",
                   "param", parseArg.findOption("-within").getOptParams().get(1));
  }
  
  /**
   * Test isOptParam() method.
   */
  @Test
  public void testIsOptParam() {
    assertEquals("Testing method isOptParam with an invalid option param : -v",
        false, parseArg.isOptParam(args[0]));
    assertEquals("Testing method isOptParam with a valid option param : -verbose",
        false, parseArg.isOptParam(args[1]));
    assertEquals("Testing method isOptParam with a valid option param : -sort",
        true, parseArg.isOptParam(args[2]));
    assertEquals("Testing method isOptParam with a valid option param : \"library\"",
        false, parseArg.isOptParam(args[3]));
    assertEquals("Testing method isOptParam with a valid option param : -within",
        true, parseArg.isOptParam(args[4]));
    assertEquals("Testing method isOptParam with a valid option param : \"1\"",
        false, parseArg.isOptParam(args[5]));
    assertEquals("Testing method isOptParam with a valid option param : \"param\"",
        false, parseArg.isOptParam(args[6]));
  }
  
  /**
   * Test exists option methods.
   */
  @Test
  public void testOptionExists() {
    assertEquals("Testing method isOptionExists with an existing option of \"-verbose\"", 
        true, parseArg.isVerbose());
    assertEquals("Testing method isOptParamExists with an existing option of \"-sort\"", 
        true, parseArg.isSort());
    assertEquals("Testing method isOptParamExists with an existing option of \"-within\"",
        true, parseArg.isWithin());
    assertEquals("Testing method isOptParamExists with an existing option of \"-console\"",
        true, parseArg.isConsole());
    assertEquals("Testing method isOptParamExists with an existing option of \"-email\"", 
        true, parseArg.isEmail());
    assertEquals("Testing method isOptParamExists with an existing option of \"-wakeup\"", 
        true, parseArg.isWakeup());
  }
  
  /**
   * Test options with parameters.
   */
  @Test
  public void testOptionParams() {
    assertEquals("Testing method to get sort type given option value of \"-sort\"",
        "library", parseArg.sortType());
    assertEquals("Testing method to get within value given option of \"-within\"", 
        1, parseArg.withinNum());
  }
}
